package com.nuanshui.heatedloan.order.integration.execute.handler.syshandler;

import com.alibaba.dubbo.config.annotation.Reference;
import com.nuanshui.heatedloan.constant.GlobalParam;
import com.nuanshui.heatedloan.order.integration.annotation.OrderExecuteAnnotation;
import com.nuanshui.heatedloan.order.integration.bean.OrderResult;
import com.nuanshui.heatedloan.order.integration.constant.OrderHandlerOrderNum;
import com.nuanshui.heatedloan.order.integration.execute.handler.OrderHandler;
import com.nuanshui.heatedloan.order.integration.form.OrderExecuteForm;
import com.nuanshui.heatedloan.task.facade.QuartzTaskManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;

/**
 * @Author: Gonzo
 * @Date 2017/4/13下午6:46
 * @since 1.4.2
 */
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@OrderExecuteAnnotation(value="expireTaskOrderandler", order = OrderHandlerOrderNum.ORDER_EZPIRE_TASK)
public class ExpireTaskOrderandler implements OrderHandler {

    @Reference(url= GlobalParam.TASK_DUBBO_SERVER,timeout=GlobalParam.DUBBO_SERVER_TIME_OUT,version=GlobalParam.TASK_DUBBO_SERVER_VERSION)
    private QuartzTaskManager quartzTaskManager;

    @Value("${order.expire.time}")
    public String orderExpireTime = "";

    @Value("${order.over.time}")
    public String orderOverTime = ""; //订单的未支付过期时间, 使用和上面同一个

    protected Logger logger = LoggerFactory.getLogger("appointment_order");

    private OrderHandler nextOrderhandler;


    @Override
    public OrderResult placeOrder(OrderExecuteForm form, OrderResult result) {
        return result;
    }

    @Override
    public OrderResult paySuccessOrder(OrderExecuteForm form, OrderResult result) {
        this.nextOrderhandler.paySuccessOrder(form, result);

        return  result;
    }

    @Override
    public OrderResult cancelOrder(OrderExecuteForm form, OrderResult result) {
        return this.nextOrderhandler.cancelOrder(form, result);
    }

    @Override
    public OrderResult verifyAppointmentOrder(OrderExecuteForm form, OrderResult result) {
        return this.nextOrderhandler.verifyAppointmentOrder(form, result);
    }

    @Override
    public void setNextOrderHandler(OrderHandler orderHandler) {
        this.nextOrderhandler = orderHandler;
    }
}
